package cn.jluzh.blog.mapper;

import cn.jluzh.blog.modules.comment.dto.ChildCommentDto;
import cn.jluzh.blog.modules.comment.entity.SysComment;
import cn.jluzh.blog.modules.comment.vo.SysCommentVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SysCommentMapper extends BaseMapper<SysComment> {

    @Select("SELECT vc.*, vu.avatar_name,vu.nickname FROM sys_comment vc LEFT JOIN sys_user vu ON vc.user_id=vu.id\n" +
            "    WHERE vc.article_id=#{id} AND vc.level_flag='0' ORDER BY vc.create_time DESC")
    List<SysCommentVo> queryArticleComments(Long id);

    @Select(" SELECT vc.*, vu.avatar_name,vu.nickname FROM sys_comment vc LEFT JOIN sys_user vu ON vc.user_id=vu.id\n" +
            "        WHERE vc.article_id=#{articleId} AND vc.parent_id=#{parentId} ORDER BY vc.create_time ASC")
    List<SysCommentVo> queryChildrenComments(ChildCommentDto dto);

    @Delete("delete from sys_comment where id=#{id} or parent_id=#{id}")
    boolean deleteComments(Long id);

    @Select("select count(*) from sys_comment where id=#{id} or parent_id=#{id}")
    Integer getDeleteTotalById(Long id);
}
